package P1线性结构;

import java.io.File;
//目录遍历
public class DirectoryTraversal {
    public static void main(String[] args) {
        File dir = new File("C:\\Users\\Administrator\\Desktop\\DSA2024.01.16");
        LinkedList<File> queue = new LinkedList<>();
        queue.offer(dir);
        while (!queue.isEmpty()) {
            File cur = queue.poll();
//            System.out.println("【" + cur.getName() + "】");
            File[] files = cur.listFiles();
            if (files == null || files.length == 0) {
                continue;
            }
            for (File file : files) {
                if (file.isFile() && file.getName().endsWith(".java")) {
                    System.out.println(file.getName());
                } else {
                    queue.offer(file);
                }
            }
        }
    }
}
